package adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.tdam_2012_g7.R;

import entidades.ContactoEmail;

public class ItemEmailAdapter extends ArrayAdapter<ContactoEmail>{
	
	private ArrayList<ContactoEmail> items;
	
	public ItemEmailAdapter(Context context, int textViewResourceId,
			ArrayList<ContactoEmail> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) this.getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			v = vi.inflate(R.layout.item_email, null);
		}
		ContactoEmail email = items.get(position);
		if (email != null) {
			TextView numero = (TextView) v.findViewById(R.id.txtEmailContacto);
			TextView tipoNumero = (TextView) v.findViewById(R.id.txtTipoEmail);
			
			numero.setText(email.getValue());
			switch (Integer.parseInt(email.getType())) {
	        case 1:
	        	tipoNumero.setText("Home");
	        	break;
	        case 2:
	        	tipoNumero.setText("Mobile");
	        	break;
	        case 3:
	        	tipoNumero.setText("Work");
	        	break;
	        case 4:
	        	tipoNumero.setText("Fax");
	        	break;
	        case 7:
	        	tipoNumero.setText("Other");
	        	break;
	        default:
	        	tipoNumero.setText("Other");
	        	break;
	        }
			
		}
		
		
		return v;
	}

}